<?php
    /**
    * Real Estate Request Module
    */
    class rsrequestmodule {
        function name() { return "Real Estate Request"; }
        function description() { return "Request a real estate, for un-register and member"; }
        function author() { return "ABSoft.vn"; }

        function hasSources() { return true; }
        function hasContent() { return true; }
        function hasViews() { return true; }

        function supportsWorkflow() { return false; }

        function retPermissions()
        {
            return array('administrate','configure','create','edit','delete');  
        }

        function permissions($internal = "") {
            return array(
            'administrate'=>'Administrate',
            'configure'=>'Configure',
            'edit'=>'Edit Links',
            'delete'=>'Delete Links'
            );
        }

        function show($view,$loc = null, $title = "") {
            global $db;

            $config = $db->selectObject('rsrequestmodule_config',"location_data='".serialize($loc)."'");
            if ($config == null) {
                echo "You should configure this module first";
            }
            else
            {
                $provinces=$db->selectObjects("provinces");        
                if (exponent_users_isLoggedIn() && (
                exponent_permissions_check("create",$loc) ||
                exponent_permissions_check("edit",$loc) ||
                exponent_permissions_check("delete",$loc) || 
                exponent_users_isAdmin()
                ))
                {
                    $view="Default"; // switch to default so user can manage items
                }
                // feb 11, 2011 - trungdt - end
                $template = new template('rsrequestmodule',$view,$loc);
                $template->assign('config',$config);
                $template->assign('moduletitle',$title);
                $template->assign('provinces',$provinces);
                $template->register_permissions($this->retPermissions(),$loc);
                $template->output();
            }		

        }

        function deleteIn($loc) {
            global $db;
            $db->delete('rsrequest_item',"location_data='".serialize($loc)."'");
        }

        function copyContent($oloc,$nloc) {
            foreach ($db->selectObjects('rsrequest_item',"location_data='".serialize($oloc)."'") as $l) {
                $l->location_data = serialize($nloc);
                $db->insertObject($l,'rsrequest_item');
            }
        }

        function searchName() {
            return false; // this module does not support search
        }

        // This function return date format for module rsrequest
        // request = 1: Yêu cầu cách đây
        // request = 0: respone , trả lời cách đây
        function _dateFormat($date_time, $request=1, $short_mode=false)
        {
            $now=time();  
            $date_translate = exponent_lang_loadFile('subsystems/forms/controls/yuicalendarcontrol.php');
            if ($now - $date_time < 86400 )  // 24 hours
            {

                $un_equal=$now-$date_time;
                $uh=floor($un_equal / 3600);
                $un_equal=$un_equal-3600*$uh;

                $um=floor($un_equal / 60);
                $un_equal=$un_equal-60*$um; 
                
                $date_time="";
                if ($request == 1)
                    $date_time = $date_translate['request'];
                else
                    $date_time = $date_translate['answer'];
                if ($uh > 0)
                {
                    $date_time.="{$uh} " . $date_translate['hour'];
                }

                if ($um > 0)
                {
                    $date_time.="{$um} " . $date_translate['minute'];
                }

                if ($un_equal > 0)
                {
                    $date_time.="{$un_equal} " . $date_translate['sec'];
                }
            }
            else
            {   
                if ($short_mode == true)
                {
                    $date_time = date('d/m/Y H:i', $date_time);
                }
                else
                {
                    $datetime = date('l, F d, o g:i a', $date_time);
                    // If the language is english, use the default language of yui calendar
                    if (USE_LANG != 'eng_US') {
                        // Translate days of the week
                        // thứ
                        $datetime=$date_translate[strtolower(substr(date('l',$date_time),0,2))].", ";
                        // ngày
                        $datetime.=date('d',$date_time)." ";
                        // tháng
                        $datetime.=$date_translate[strtolower(date('F',$date_time))]." ";
                        // năm
                        $datetime.=date('o',$date_time)."; ";
                        $datetime.=date('g:i',$date_time)." ";
                        // am - pm
                        $datetime.=$date_translate[strtolower(date('a',$date_time))];
                        $date_time = $datetime;
                    }
                }
            }
            return $date_time;
        }
    }

?>
